/**
 * 
 */
package com.swim.recruitment.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.swim.recruitment.entity.Resume;
import com.swim.recruitment.service.ResumeService;

/**
 * 求职简历Controller
 * @author ljw
 * @version 2023-04-13
 */
@Controller
@RequestMapping(value = "${adminPath}/recruitment/resume")
public class ResumeController extends BaseController {

	@Autowired
	private ResumeService resumeService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public Resume get(String id, boolean isNewRecord) {
		return resumeService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("recruitment:resume:view")
	@RequestMapping(value = {"list", ""})
	public String list(Resume resume, Model model) {
		model.addAttribute("resume", resume);
		return "swim/recruitment/resumeList";
	}
	
	/**
	 * 查询列表数据
	 */
//	@RequiresPermissions("recruitment:resume:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<Resume> listData(Resume resume, HttpServletRequest request, HttpServletResponse response) {
		Page<Resume> page = resumeService.findPage(new Page<Resume>(request, response), resume); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("recruitment:resume:view")
	@RequestMapping(value = "form")
	public String form(Resume resume, Model model) {
		model.addAttribute("resume", resume);
		return "swim/recruitment/resumeForm";
	}

	/**
	 * 保存求职简历
	 */
//	@RequiresPermissions("recruitment:resume:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated Resume resume) {
		resumeService.save(resume);
		return renderResult(Global.TRUE, text("保存求职简历成功！"));
	}
	
	/**
	 * 删除求职简历
	 */
	@RequiresPermissions("recruitment:resume:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(Resume resume) {
		resumeService.delete(resume);
		return renderResult(Global.TRUE, text("删除求职简历成功！"));
	}
	
	/**
	 * 获取详情数据
	 */
	@RequestMapping(value = "detailsData")
	@ResponseBody
	public String detailsData(String resumeId) {
		return renderResult(Global.TRUE, text("获取详情数据成功！"), resumeService.get(resumeId));
	}
	
}